﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Demo01.Repsotories;
using System.Windows.Forms;
using WindowsFormsApp1.Models;

namespace WindowsFormsApp1.Respostories
{
    public class RoleRespostoriy
    {
        //获取角色列表
        public static List<Role> GetRoles()
        {
            List<Role> roles = null;//定义角色列表
            SqlDataReader reader = null;//定义数据读取器
            try
            {
                reader = DBHelper.Query("SELECT * FROM Roles");
                roles = new List<Role>();//实例化 roles 列表
                while (reader.Read())
                {
                    Role role = new Role();
                    role.Id= reader.GetInt32(0);//获取角色ID
                    role.Name = reader.GetString(1);//获取角色名称
                    role.Weight= reader.GetInt32(2);//获取权重
                    roles.Add(role);//添加角色到列表
                }
            }
            catch (SqlException ex)
            {
                MessageBox.Show(" 角色权限列表信息,读取数据库失败：" + ex.Message);
            }
            finally
            {
                reader.Close();
            }

            return roles;
        }





    }
}
